package com.hoshiicloud.payment.feign.fallback;

import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.payment.feign.UploadService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * @program: hoshiicloud
 * @description: 文件服务熔断
 * @author: Mr.wu
 * @create: 2019-06-04 10:59
 **/
@Component
@Slf4j
public class UploadServiceFeignFallbackFactory implements FallbackFactory<UploadService> {

    @Override
    public UploadService create(Throwable throwable) {
        log.error("fallback; reason was:" + throwable.toString());
        return new UploadService() {
            @Override
            public Response test() {
                return null;
            }

            @Override
            public Response fileUpload(String bucketName, String objectKey, String fileName,
                    String folder, Boolean privateOwned, MultipartFile file) {
                return Response.failed("上传失败");
            }
        };
    }
}
